package main

import (
	"github.com/cloudwego/netpoll"
	"time"
)

// 注意：暂时不支持udp.
func main() {
	network, address, timeout := "udp", "127.0.0.1:8089", 50*time.Millisecond

	// use dialer
	dialer := netpoll.NewDialer()

	// 不支持udp?.
	conn, err := dialer.DialConnection(network, address, timeout)
	if err != nil {
		panic("dial netpoll connection failed")
	}

	writer := conn.Writer()
	_, _ = writer.WriteString("hello world!")
	_ = writer.Flush()

	time.Sleep(time.Second)
	_, _ = writer.WriteString("hello china!")
	_ = writer.Flush()

	time.Sleep(time.Second)
	_, _ = writer.WriteString("hello guangzhou!")
	_ = writer.Flush()
	_ = conn.Close()
}
